/**
 * Created by Admin on 2018/1/15.
 */
define(function(require,exports,module) {
    var commonPaging = require("../common/commonPagingCq.js");
    var tpl = require("./tpl/monitorCollectTpl.html");
    var template = require("template");
    require("../common/dialog.js");
    require("../common/qy-template");
    require("../seajs-init");

    /*获取区域和类型*/
    var List = {
        getTimeInfos: function () {
            /*获取监控汇总相关参数*/
            $.ajax({
                url: window.jkconfig.webapiurlv + "monitorsum/suminfo",
                success: function (data) {
                    if (data.code == 0) {
                        $(".expiration_month").html(data.expiration.months );
                        $(".expiration_count").html(data.expiration.count);
                        $(".yearIn").html(data.yearIn);
                        $(".yearOut").html(data.yearOut);
                        $(".yearExpiry").html(data.yearExpiry);
                    } else {
                        $.showErr("获取汇总信息失败！");
                    }
                }
            })
        }
    }
    List.getTimeInfos();

    var p = new commonPaging({
        htmlContainer: "#Js_page_content",
        pageContainer: "#Js_fs_paging",
        url: window.jkconfig.webapiurlv + "monitorsum/list",
        tpl: tpl,
        data: $("#searchForm").serialize()
    });
    p.init();

    $(function () {
        $("body").on("click", ".ptmt-curpointer", function () {
            if ($(this).children(".up").length > 0) {
                $(this).children(".up").removeClass("up").addClass("down");
                $("[name=order]").val("asc");
                $("[name=sort]").val($(this).attr("data-sort"));
                $("[name=pageSize]").val(15);
                $.ajax({
                    url: window.jkconfig.webapiurlv+ "monitorsum/list",
                    data:$("#searchForm").serialize(),
                    success:function(data){
                        var html = template.compile(tpl)({data: data})
                        $("#Js_page_content").html(html);
                    }
                })
            } else {
                $(this).children(".down").removeClass("down").addClass("up");
                $("[name=order]").val("desc");
                $("[name=sort]").val($(this).attr("data-sort"));
                $("[name=pageSize]").val(15);
                $.ajax({
                    url: window.jkconfig.webapiurlv+ "monitorsum/list",
                    data:$("#searchForm").serialize(),
                    success:function(data){
                        var html = template.compile(tpl)({data: data})
                        $("#Js_page_content").html(html);
                    }
                })
            }
        }).on("click", ".btnSearch", function () {
            $("[name=pageSize]").val(15);
            $("[name=applicantName]").val($.trim($("[name=applicantName]").val()));
            if($("#Js_fs_paging").css("display") == "block"){
                p.page.destroy && p.page.destroy();
                $("[name=pageNumber]").val(1);
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: window.jkconfig.webapiurlv+ "monitorsum/list",
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            }else{
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: window.jkconfig.webapiurlv+ "monitorsum/list",
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            }
        }).on("click",".btnExport",function(){
            $("[name=pageSize]").val(5000);
            window.location.href = window.jkconfig.webapiurlv + "monitorsum/listexport?"+$("#searchForm").serialize()+"&"+api_key+"="+token;
        })
    })
})
